package com.example.demo1115.service.impl;

import com.example.demo1115.dao.BookDao;
import com.example.demo1115.entity.Book;
import com.example.demo1115.service.BookService;
import com.example.demo1115.vo.Result;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;
    @Override
    public Result findAll(Integer current,Integer pageSize){
        System.out.println("current = " + current);
        System.out.println("pageSize = " + pageSize);
        PageHelper.startPage(current,pageSize);
        List<Book> all = bookDao.findAll();
        PageInfo<Book> pageInfo=new PageInfo<>(all);
        return new Result(200,"查询成功",pageInfo);
    }

    @Override
    public Result insertone(String isbn, String bookName, int price) {
            int insertone = bookDao.insertone(isbn,bookName,price);
            return new Result(200,"插入成功",insertone);
        }

    @Override
    public Result updateone(String isbn, String bookName, int price) {
        int updateone = bookDao.updateone(isbn, bookName, price);
        return new Result(200,"更新成功",updateone);
    }

    @Override
    public Result deleteByisbn(String isbn) {
        int i = bookDao.deleteByisbn(isbn);
        return new Result(200,"更新成功",i);
    }
}
